﻿@using FwProject.Distribution.Dto
@using FwProject.ManagerConfig.Dto
@model List<MakingReceiptOutputDto>
@section styles{

}
@{
    int index = 0;
    ConfigInfoDto config = ViewBag.Config;
}
<div id="obj_FormDiv" style="font-size:12px;position:absolute;padding-left:3px;width:100%;overflow: auto">
    <div align='center' id="cxReceiptForm_result_msg" style="color:red;margin-top:5px"></div>
    <form id="cxReceiptForm" action="@Url.Action("ModifyMakingReceipt")" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="SuccessAjaxCallbackgoback" data-ajax-failure="NewFailureAjaxCallback" data-ajax-begin="AjaxBegin" data-ajax-method="Post" role="form" style="background-color: rgba(255, 255, 255, 0.8);">
        <div class="ibox-title">
            <h5>定时结账周期打印收据</h5>
            <div class="ibox-tools">
                <button type="button" class="btn btn-primary btn btn-sm" id="btn">保存</button>
            </div>
        </div>
        <div class="ibox-content">
            <div class="alert alert-danger">
                共 <small class="text-navy">@(Model.Count)</small> 条收据,其中有 <small class="text-navy" id="labelCount">@(Model.Sum(o => o.IsZeroCount))</small> 个货品单价为0
                点击 <a class="alert-link" href="javascript:void(0)" onclick="jumpFirst()">查看</a> 第一个单价为0的货品

            </div>
        </div>
        <input type="hidden" id="deleteIds" name="deleteIds">
        <input type="hidden" name="beginTime" value="@Model.FirstOrDefault()?.BeginTime" />
        <input type="hidden" name="endTime" value="@Model.FirstOrDefault()?.EndTime" />
        <div style="width:100%;text-align: center;color:#000000;">&nbsp;共&nbsp;<span name="totalNum">@Model.Count</span>&nbsp;条&nbsp;</div>

        @foreach (var item in Model)
        {
            <table name="mainTable" style="width:100%;height:auto;text-align: center;padding-bottom:50px;padding-top:30px;">
                <tr>
                    <td align='center' style='width:100%;'>
                        <table cellSpacing=0 cellPadding=0 style="width: 600px">
                            <tr>
                                <td align="center" width="100%" style="font-size: 24px;color:#000000;height: 30px;" colspan="4">
                                    收&nbsp;&nbsp;款&nbsp;&nbsp;收&nbsp;&nbsp;据
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="4" style="height: 30px">
                                    @(DateTime.Now.ToString("yyyy-MM-dd"))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No&nbsp;<span name='sjCode'>00000029</span>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="deleteRow(this,'@item.Id');">删除</a>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="4">
                                    <table name="justForJeDis" align='left' width='600px' cellSpacing=0 cellPadding=0 style='border: 1px solid #000000;'>
                                        <tr>
                                            <td align="center" style='color: #000000;font-size: 16px;width: 100px;padding:5px;'>今&nbsp;&nbsp;收&nbsp;&nbsp;到</td>
                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                <input type="hidden" name="MakingReceipts[@index].ReceiptId" value="@item.Id" />
                                                <input type="hidden" name="MakingReceipts[@index].Restaurantid" value="@item.RestaurantId" />
                                                &nbsp;餐厅@(item.RestaurantName)&nbsp;@(item.BeginTime.Month)月份餐具（@(item.BeginTime.ToString("yyyy-MM-dd"))&nbsp;~&nbsp;@(item.EndTime.ToString("yyyy-MM-dd"))）
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" style="color: #000000;font-size: 16px;">配&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;送</td>
                                            <td width='495px'>
                                                <table align='left' width='495px' cellSpacing=0 cellPadding=0>
                                                    @{
                                                        int j = 0;
                                                    }
                                                    @foreach (var i in item.Suits)
                                                    {
                                                        <tr>
                                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                                <input type="hidden" name="MakingReceipts[@index].TypeNumber[@j].TypeNumberId" value="@i.TypeNumberId" />
                                                                @(i.Name)：
                                                            </td>
                                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                                <span name="slPackagePs">@(i.Quantity)</span>
                                                                套
                                                            </td>

                                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                                <input type="hidden" name="MakingReceipts[@index].TypeNumber[@j].TypeNumberoldPrice" value="@i.Price"/>
                                                                <input type="hidden" name="MakingReceipts[@index].TypeNumber[@j].TypeNumberPrice" value="@i.Price" />
                                                                x&nbsp; <input type='text' name="djPrice" size="10" onkeyup="djTxtChange(this,'2');" class="ui-widget-content ui-corner-all " value="@(i.Price)" />
                                                            </td>
                                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                                =&nbsp;<span name='jeMoney'>@(i.Total)</span>元
                                                            </td>
                                                        </tr>
                                                        <span style="display:none;"> @(j++)</span>
                                                    }
                                                </table>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td align="center" style='color: #000000;font-size: 16px;width: 100px;'>优&nbsp;惠&nbsp;金&nbsp;额</td>
                                            <td align='left' style='border-bottom: 1px solid #000000;height: 35px;font-size: 14px'>
                                                <input type="hidden" name="MakingReceipts[@index].DiscountedPrice" value="0.00" />
                                                <input type='text' name="jeDis" style="width: 20%" oninput="disTxtChange(this);" class="ui-widget-content ui-corner-all " max="99999999" value="0.00" />&nbsp;元
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center">
                                                <div align="center" style='color: #000000;font-size: 16px;width: 100px;'>
                                                    <div>金&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;额</div>
                                                    <div>人&nbsp;&nbsp;民&nbsp;&nbsp;币</div>
                                                </div>
                                            </td>
                                            <td style='border-bottom: 1px solid #000000'>
                                                <table width='100%' cellSpacing=0 cellPadding=0>
                                                    <tr>
                                                        <td align='left' style='color: #000000;font-size: 16px;width: 60px;'>(大写)</td>
                                                        <td align="left" style='font-size: 16px;'>
                                                            <span name='jeAccountUpper'> @(item.Capital) </span>&nbsp;&nbsp;&nbsp;
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" style='color: #000000;font-size: 16px;width: 100px;height: 40px;'>
                                                备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注
                                            </td>
                                            <td>
                                                <table width='100%' cellSpacing=0 cellPadding=0>
                                                    <tr>
                                                        <td width='395px' align='left'><input type='text' name="MakingReceipts[@index].Remarks" style="width: 90%" class="ui-widget-content ui-corner-all" value="@item.RemarksConten" /></td>
                                                        <td nowrap style='border-left: 1px solid #000000;font-size: 16px;width: 100px;height: 40px;'>
                                                            &nbsp;￥
                                                            <input type="hidden" name="MakingReceipts[@index].Sum" value="@(item.Sum)" />
                                                            <span width='95px' name='jeAccount'>@(item.Sum)</span>元
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr align="left" width="100%">
                                <td style="font-size: 14px;color:#000000;height: 30px;padding-right:100px;">&nbsp;&nbsp;单位盖章</td>
                                <td style="font-size: 14px;color:#000000;height: 30px;padding-right:10px;">会计：@(config.Accountant)</td>
                                <td style="font-size: 14px;color:#000000;height: 30px;padding-right:10px;">出纳：@(config.Cashier)</td>
                                <td style="font-size: 14px;color:#000000;height: 30px">经手人：@(config.AgentPerson)</td>
                            </tr>
                        </table>
                </tr>

            </table>
            <span style="display:none;">@(index++)</span>

        }
        <br />

    </form>

</div>
@section scripts{
    <script src="~/js/common.js"></script>
    <script src="~/js/jquery-ui-util.js"></script>
    <script src="~/js/MakingReceipt.js"></script>

    <script type="text/javascript">
        function radio_click(obj) {
            var span = $("#checkDialogSpan");
            if (obj.value == '1') {
                span.css("display", "block");
            } else {
                span.css("display", "none");
            }
        }
        function convertCurrency(currencyDigits) {
            // Constants:
            var MAXIMUM_NUMBER = 99999999999.99;
            // Predefine the radix characters and currency symbols for output:
            var CN_ZERO = "零";
            var CN_ONE = "壹";
            var CN_TWO = "贰";
            var CN_THREE = "叁";
            var CN_FOUR = "肆";
            var CN_FIVE = "伍";
            var CN_SIX = "陆";
            var CN_SEVEN = "柒";
            var CN_EIGHT = "捌";
            var CN_NINE = "玖";
            var CN_TEN = "拾";
            var CN_HUNDRED = "佰";
            var CN_THOUSAND = "仟";
            var CN_TEN_THOUSAND = "万";
            var CN_HUNDRED_MILLION = "亿";
            var CN_SYMBOL = "";
            var CN_DOLLAR = "元";
            var CN_TEN_CENT = "角";
            var CN_CENT = "分";
            var CN_INTEGER = "整";
            // Variables:
            var integral; // Represent integral part of digit number.
            var decimal; // Represent decimal part of digit number.
            var outputCharacters; // The output result.
            var parts;
            var digits, radices, bigRadices, decimals;
            var zeroCount;
            var i, p, d;
            var quotient, modulus;
            // Validate input string:
            currencyDigits = currencyDigits.toString();
            if (currencyDigits == "") {
                return "还没有输入数字！";
            }
            if (currencyDigits.match(/[^,.\d]/) != null) {
                return "请输入有效数字!";
            }
            if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
                return "请输入有效格式数字！";
            }
            // Normalize the format of input digits:
            currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
            currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
            // Assert the number is not greater than the maximum number.
            if (Number(currencyDigits) > MAXIMUM_NUMBER) {
                return "您输入的数字太大了!";
            }
            // Process the coversion from currency digits to characters:
            // Separate integral and decimal parts before processing coversion:
            parts = currencyDigits.split(".");
            if (parts.length > 1) {
                integral = parts[0];
                decimal = parts[1];
                // Cut down redundant decimal digits that are after the second.
                decimal = decimal.substr(0, 2);
            }
            else {
                integral = parts[0];
                decimal = "";
            }
            // Prepare the characters corresponding to the digits:
            digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
            radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
            bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
            decimals = new Array(CN_TEN_CENT, CN_CENT);
            // Start processing:
            outputCharacters = "";
            // Process integral part if it is larger than 0:
            if (Number(integral) > 0) {
                zeroCount = 0;
                for (i = 0; i < integral.length; i++) {
                    p = integral.length - i - 1;
                    d = integral.substr(i, 1);
                    quotient = p / 4;
                    modulus = p % 4;
                    if (d == "0") {
                        zeroCount++;
                    }
                    else {
                        if (zeroCount > 0) {
                            outputCharacters += digits[0];
                        }
                        zeroCount = 0;
                        outputCharacters += digits[Number(d)] + radices[modulus];
                    }
                    if (modulus == 0 && zeroCount < 4) {
                        outputCharacters += bigRadices[quotient];
                    }
                }
                outputCharacters += CN_DOLLAR;
            }
            // Process decimal part if there is:
            if (decimal != "") {
                for (i = 0; i < decimal.length; i++) {
                    d = decimal.substr(i, 1);
                    if (d != "0") {
                        outputCharacters += digits[Number(d)] + decimals[i];
                    }
                }
            }
            // Confirm and return the final output string:
            if (outputCharacters == "") {
                outputCharacters = CN_ZERO + CN_DOLLAR;
            }
            if (decimal == "") {
                outputCharacters += CN_INTEGER;
            }
            outputCharacters = CN_SYMBOL + outputCharacters;
            return outputCharacters;
        }
        var boo = true;
        $("#btn").on("click", function () {
            if (boo == false) {
                layer.msg("您已经保存过该收据！")
                return false;
            }
            $("#cxReceiptForm").submit();
            boo = false;
        })

        function SuccessAjaxCallbackgoback(data) {
            layer.closeAll();
            if (data.success) {
                layer.confirm('保存成功', {
                    btn: ['确定'] //按钮
                }, function () {
                     top.closeAndRefreshTab("@Url.Action("MakingReceiptDetails")");
                });
            } else {
                boo=true
                layer.msg('操作失败：' + data.error.message, {
                    icon: 2,
                });

            }
        }

        function NewFailureAjaxCallback(xhr, status, thrown) {
            boo = true
            FailureAjaxCallback(xhr, status, thrown);
        }

    </script>
}
